# _*_ encoding:utf-8 _*_
from __future__ import unicode_literals
from datetime import datetime

from django.db import models

# Create your models here.


class CityDict(models.Model):
    name = models.CharField(max_length=20,verbose_name=u"城市")
    desc = models.CharField(max_length=200,verbose_name=u"描述")
    add_time = models.DateTimeField(default=datetime.now,verbose_name=u"添加时间")

    class Meta:
        verbose_name = u"城市"
        verbose_name_plural = verbose_name
    def __unicode__(self):
        return self.name


class CourseOrg(models.Model):
    name = models.CharField(max_length=50,verbose_name=u"机构名称")
    catgory = models.CharField(default="pxjg",verbose_name=u"机构类别",max_length=20,choices=(("pxjg","培训机构"),("gx","高校"),("gr","个人")))
    desc = models.TextField(verbose_name=u"机构描述")
    click_nums = models.IntegerField(default=0,verbose_name=u"点击数")
    fav_nums = models.IntegerField(default=0,verbose_name=u"收藏数")
    image = models.ImageField(upload_to="org/%Y%m",verbose_name=u"封面图")
    address = models.CharField(max_length=150,verbose_name=u"机构地址")
    city = models.ForeignKey(CityDict,verbose_name=u"添加城市")
    students = models.IntegerField(default=0,verbose_name=u"学习人数")
    course_num = models.IntegerField(default=0,verbose_name=u"课程数")
    add_time = models.DateTimeField(default=datetime.now,verbose_name=u"添加时间")

    class Meta:
        verbose_name = u"课程机构"
        verbose_name_plural = verbose_name
    def __unicode__(self):
        return self.name

    def course_teache_num(self):
        return self.teacher_set.all().count()


class Teacher(models.Model):
    org = models.ForeignKey('CourseOrg', verbose_name='所属机构')
    name = models.CharField(max_length=50,verbose_name=u"教师名称")
    work_years = models.IntegerField(default=0,verbose_name=u"工作年限")
    work_company = models.CharField(max_length=50,verbose_name=u"公司名称")
    work_position = models.CharField(max_length=50,verbose_name=u"公司职称")
    points = models.CharField(max_length=50,verbose_name=u"教学特点")
    click_nums = models.IntegerField(default=0, verbose_name=u"点击数")
    fav_nums = models.IntegerField(default=0, verbose_name=u"收藏数")
    image = models.ImageField(default= '',upload_to="teacher/%Y%m", verbose_name=u"教师头像")
    add_time = models.DateTimeField(default=datetime.now,verbose_name=u"添加时间")

    class Meta:
        verbose_name = u"教师"
        verbose_name_plural = verbose_name

    def __unicode__(self):
            return self.name
